%{
#include "id.h"
#include "axspec.h"
#include "axspeclist.h"

#define YYSTYPE void*

int non_empty;
%}

%token SELECT FROM ID ON NON EMPTY

%%

/**
 * Select statement
 */

  select_statement:
    SELECT axis_specification_list
    FROM ID {
                     char buf[256];
                     printf("nombre del cubo: %s\n", idGet($4, buf));
                     axspeclist_dump($2);
                   }

/**
 * Axis specification
 */

  axis_specification_list:
    axis_specification
    {
      struct axspeclist *axspeclist = axspeclist_create();
      axspeclist_add(axspeclist, $1);
      $$ = axspeclist;
    }
    | axis_specification ',' axis_specification_list
    {
      axspeclist_add($3, $1);
      $$ = $3;
    }

  axis_specification:
    non_empty_opt expression dim_props_opt ON ID
    {
      char buf[256];
      $$ = axspec_create(non_empty, 0, idGet($5, buf));
    }

  non_empty_opt:
    {
      non_empty = 0;
    }
    | NON EMPTY
    {
      non_empty = 1;
    }

  dim_props_opt: | dim_props;

  dim_props: ;

  expression: expression ':' value_expression | value_expression;

  value_expression: term;

  term: factor;

  factor: value_expression_primary;

  value_expression_primary:
    ID;

/**
 * Generic non-terminals
 */

compound_id: identifier;

identifier: ID;

%%

